package com.ellecity06.cwhiskymall.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ellecity06.common.ktx.load
import com.ellecity06.common.viewholder.ViewBindingHolder
import com.ellecity06.cwhiskymall.bean.response.AppMenuSettingRespone
import com.ellecity06.cwhiskymall.databinding.ItemHomeCategoryBinding

/**
 * @author ellecity06
 * @time 2024/10/23 17:36
 * @des 金刚区
 */
class HomeCategoryAdapter(recyclerView: RecyclerView) :
    BaseQuickAdapter<AppMenuSettingRespone.SettingWebLayoutVOS.DetailVO, ViewBindingHolder<ItemHomeCategoryBinding>>() {
    private val mWidth: Int by lazy { recyclerView.measuredWidth }
    override fun onBindViewHolder(
        holder: ViewBindingHolder<ItemHomeCategoryBinding>,
        position: Int,
        item: AppMenuSettingRespone.SettingWebLayoutVOS.DetailVO?
    ) {
        holder.binding.icon.load(context, item?.image)
        holder.binding.name.text = item?.name

    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): ViewBindingHolder<ItemHomeCategoryBinding> {
        val view = ItemHomeCategoryBinding.inflate(LayoutInflater.from(context), parent, false)
        //每个item平分整个屏幕的宽度
        val params = view.root.layoutParams
        params.width = mWidth / 5
        return ViewBindingHolder(view)
    }
}